<template>
	<view class="customer">
		<view class="cusImg">
			<u--image :src="avatar" shape="circle" width="100" height="100">
			</u--image>
		</view>
		<view class="subInfo">
			<u--form :model="formData" :rules="rules" ref="form1">
				<u-form-item label="姓名" prop="name" ref="item1" labelWidth="150" labelPosition="top">
					<u--input v-model="formData.name" border="surround" placeholder="请输入姓名"></u--input>
				</u-form-item>
			</u--form>
			<view class="addpro">
				<u-button class="custom-style" text="提交"
					customStyle="background: linear-gradient(90deg, #0873DE 0%, #C7EACE 100%);color:#fff;margin-top:20px;border-radius: 30px;"
					@click="goAuth">
				</u-button>
			</view>
		</view>
	</view>
</template>
<script>
	import eventBUs from '../../utils/eventBus.js'
	import vvSelect from '@/components/vv-select/vv-select.vue'
	import {
		fillName,getUser
	} from '@/request/api.js'
	export default {
		components: {
			vvSelect
		},
		data() {
			return {
				avatar: '',
				sel: true,
				active: 0, // 选中协议与否
				formData: {
					name: '',
				},
				rules: {
					'name': {
						type: 'string',
						required: true,
						message: '请输入姓名',
						trigger: ['blur', 'change']
					}
				},
				userInfo: {},
			};
		},
		methods: {
			async getUserInfo(){
				let res =await getUser()
				uni.setStorageSync('userInfo',res.data)
				this.$eventBus.$emit('hasLogin', true);
				// console.log(res)
			},
			pickerChange(e, name) {
				// console.log(e,name)
				this.formData.ibec_id = e.toString()
				this.$refs.form1.validateField('ibec_id')
			},
			lxChange(item) {
				this.formData.type_data = item
			},
			goAuth() {
				// console.log(this.formData)
				this.$refs.form1.validate().then(res => {
					let form = {
						moniker:this.formData.name
					}
					fillName(form).then(res => {
						if (res.code == 200) {
							this.getUserInfo()
							if(this.formData.type_data == 1){
								uni.navigateTo({
									url:'/my_pages/infoAudit/infoAudit'
								})
								return false;
							}
							uni.switchTab({
								url:'/pages/my/my'
							})
						}
					})
				}).catch(errors => {
					console.log(errors)
					uni.$u.toast('请正确填写信息')
				})
			}
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			let userInfo = uni.getStorageSync('userInfo1')
			this.avatar = userInfo.avatar
			this.$nextTick(() => {
				// 在此处执行你要执行的函数
				this.$refs.form1.setRules(this.rules)
			});
		},
	};
</script>
<style lang="scss" scoped>
	::v-deep .u-form-item__body__right {
		margin-top: 25rpx !important;
	}

	::v-deep .u-radio {
		margin-right: 13rpx;
	}

	::v-deep .u-form-item__body__right__message {
		margin-left: 0 !important;
	}

	::v-deep .u-form-item__body__right__content__slot {
		z-index: 100 !important;
	}

	::v-deep .u-textarea__count {
		background-color: transparent !important;
	}

	::v-deep .u-textarea {
		background-color: transparent !important;
		color: #505050;
	}

	::v-deep .vv-input__control {
		color: #505050;
		font-size: 30rpx !important;
	}

	.popupShow {
		overflow: hidden;
		position: fixed;
		z-index: 999999999999;
	}

	::v-deep .u-transition {
		overflow: scroll;
		max-height: 70vh;
	}

	::v-deep .u-radio__text {
		font-size: 30rpx !important;
		color: #505050;
	}

	::v-deep .u-radio-group--row {
		z-index: 10;
		color: #505050;
	}

	::v-deep .u-input {
		background-color: transparent !important;
	}

	::v-deep .u-form-item__body__left__content__label {
		font-size: 30rpx !important;
		color: #979797 !important;
	}

	::v-deep .u-input__content__field-wrapper__field {
		font-size: 30rpx !important;
		color: #505050;
	}

	::v-deep .u-textarea__field {
		font-size: 30rpx !important;
		color: #505050;
	}

	.customer {
		margin: 20rpx;

		.title {
			background: rgba(0, 213, 206, 0.15);
			height: 45px;
			line-height: 45px;
			display: flex;
			align-items: center;
			font-weight: 600;

			.leftIndex {
				width: 4rpx;
				height: 34rpx;
				background: #0873DE;
				margin: 0 15rpx;
			}

			.Info {}
		}

		.compony {
			display: flex;
			border: .5px solid #dadbde;
			padding-top: 6px;
			padding-bottom: 6px;
			padding-left: 9px;
			padding-right: 9px;
			height: 24px;
			border-radius: 4px;
			justify-content: space-between;

			.select {
				flex: 1;
			}
		}

		.subInfo {
			padding: 20rpx;
		}

		.cusImg {
			display: flex;
			justify-content: center;
		}
	}
</style>
